package vn.bang.dao;

import javax.persistence.EntityManager;

import vn.bang.dao.impl.BoardDAOImpl;
import vn.bang.dao.impl.GameDAOImpl;
import vn.bang.dao.impl.PlayerDAOImpl;
import vn.bang.dao.impl.RoleDAOImpl;
import vn.bang.dao.impl.UserDAOImpl;

import com.googlecode.genericdao.dao.jpa.GenericDAOImpl;
import com.googlecode.genericdao.search.jpa.JPAAnnotationMetadataUtil;
import com.googlecode.genericdao.search.jpa.JPASearchProcessor;

public class DAOFactory {
	static public BoardDAO createBoardDAO(EntityManager entityManager) {
		BoardDAOImpl boardDAOImpl = new BoardDAOImpl();
		setUpGenericDAOImpl(boardDAOImpl, entityManager);
		return boardDAOImpl;
	}
	static public GameDAO createGameDAO(EntityManager entityManager) {
		GameDAOImpl gameDAOImpl = new GameDAOImpl();
		setUpGenericDAOImpl(gameDAOImpl, entityManager);
		return gameDAOImpl;
	}
	static public PlayerDAO createPlayerDAO(EntityManager entityManager) {
		PlayerDAOImpl playerDAOImpl = new PlayerDAOImpl();
		setUpGenericDAOImpl(playerDAOImpl, entityManager);
		return playerDAOImpl;
	}
	static public RoleDAO createRoleDAO(EntityManager entityManager) {
		RoleDAOImpl roleDAOImpl = new RoleDAOImpl();
		setUpGenericDAOImpl(roleDAOImpl, entityManager);
		return roleDAOImpl;
	}
	static public UserDAO createUserDAO(EntityManager entityManager) {
		UserDAOImpl userDAOImpl = new UserDAOImpl();
		setUpGenericDAOImpl(userDAOImpl, entityManager);
		return userDAOImpl;
	}
	@SuppressWarnings("rawtypes")
	private static void setUpGenericDAOImpl(GenericDAOImpl genericDAOImpl, EntityManager entityManager) {
		genericDAOImpl.setEntityManager(entityManager);
		genericDAOImpl.setSearchProcessor(new JPASearchProcessor(new JPAAnnotationMetadataUtil()));
	}
}
